package com.cll.pmis.controller;


import com.cll.pmis.common.Result;
import com.cll.pmis.common.security.SysUser;
import com.cll.pmis.service.IMenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 菜单管理
 * </p>
 *
 * @author chenliangliang
 * @since 2018-06-18
 */
@RestController
@RequestMapping("/menu")
public class MenuController {


    private IMenuService menuService;

    protected MenuController(IMenuService menuService) {
        this.menuService = menuService;
    }

    /**
     * 获取用户菜单
     */
    @GetMapping("/nav")
    public Result nav(SysUser sysUser, HttpSession session) {
        Object menu = session.getAttribute("menu");
        if (menu == null) {
            menu = menuService.getUserMenus(sysUser.getId());
            session.setAttribute("menu",menu);
        }
        return Result.ok(menu);
    }
}

